package com.wuxiaoqin.server.controller;

import com.alipay.easysdk.factory.Factory;
import com.wuxiaoqin.server.entity.Users;
import com.wuxiaoqin.server.service.IUsersService;
import com.wuxiaoqin.server.service.impl.AlipayService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/alipay")
public class AliPayController {
    @Autowired
    private AlipayService alipayService;
    @Autowired
    private IUsersService usersService;
    /**
     * 跳转到支付界面
     *
     * @return
     * @throws Exception
     */
    @ApiOperation(value = "支付调用接口，支付主题，和订单号，订单号尽量不要重复")
    @GetMapping("/pay")
    public String pay(@RequestParam("subject") String subject,
                      @RequestParam("orderid") Integer orderid) throws Exception {
       // Users currentUser = usersService.getCurrentUser();
        String s = alipayService.toPayPage(subject, orderid,1008);
        return s;
    }
    /**
     * @param request: 请求
     * @return java.lang.String
     * @description: 支付宝异步回调
     */
    @ApiOperation(value = "支付宝回调接口，你不用管")
    @PostMapping("/notify")
    public String notify_url(HttpServletRequest request) throws Exception {
      return   alipayService.notifyService(request);
    }

}
